CLIP.Search.enc = function(val) {
	return val.replace(/ /g, '-');
};

CLIP.Search.dec = function(val) {
	return val.replace(/-/g, ' ');
};

CLIP.Clips.initPage = 1;
CLIP.Clips.currentPage = 1;
CLIP.Clips.pageSize = 15;

CLIP.Clips.searchUrl = function(keyword) {
	return 'http://phim14.net/search/' + keyword + '/page-' + CLIP.Clips.currentPage + '.html';
};

CLIP.Clips.filterUrl = function() {
	var url = 'http://phim14.net/danh-sach/' + $('#types input:checked').val() + '/page-' + CLIP.Clips.currentPage + '.html?order_by=' + $('#sorts input:checked').val() + '&category_id='
			+ $('#cats input:checked').val();

	return url;
};

CLIP.Clips.moreHtml = function(text) {
	var html = [];

	text = bum.util.parse(text, '<div class="status">', '<div class="clear"></div>');
	if (text == null) {
		return html;
	}
	var html = [];
	$.each(text.split('<div class="status">'), function(i, clip) {
		++CLIP.Clips.moreCount;

		var code = bum.util.parse(clip, '<a href="', '"').replace('http://phim14.net/phim/', '');
		var title = bum.util.parse(clip, 'title="', '"');
		var originalTitle = bum.util.parse(clip, '<div class="name2">', '</div>');
		var img = bum.util.parse(clip, '<img src="', '"');
		if (img.indexOf('/') === 0) {
			img = 'http://phim14.net' + img;
		}
		img = 'http://img.cdn.bum.vn/fetch?' + img;

		html.push('<a class="item clip" href="#" code="', code, '"><div class="cw">');
		html.push('<img src="http://cdn.bum.vn/_.gif" style="background-image:url(', img, ');"/>');
		html.push('<div class="iw"><h4>', title, '</h4>');
		html.push('<h5>', originalTitle, '</h5></div>');
		html.push('</div></a>');
	});

	return html;
};

CLIP.Info.infoUrl = function(code) {
	// http://m.phim14.net/xem-phim/anh-hung-du-con_black-white-the-dawn-of-justice.7546.177347.html
	bum.api.fetchUrl('http://m.phim14.net/xem-phim/' + code, CLIP.Chap.headers, CLIP.Info.getChaps);

	// http://m.phim14.net/phim/anh-hung-du-con_black-white-the-dawn-of-justice.7546.html
	return 'http://m.phim14.net/phim/' + code;
};

CLIP.Info.parseInfo = function(text) {
	text = bum.util.parse(text, '<div class="content-items">', '<div class="tab-content">');
	if (text == null) {
		return null;
	}

	var poster = bum.util.parse(text, '<img src="', '"');
	if (poster) {
		poster = 'http://img.cdn.bum.vn/fetch?' + poster;
	}
	var title = bum.util.parse(text, '<h3>', '</h3>');
	var detail = bum.util.parse(text, '<ul class="info-artist">', '<li><strong>Rating');
	if (detail) {
		detail = detail.replace(/<a /g, '<span ').replace(/<\/a>/g, '<\/span>');
		detail = '<ul>' + detail + '</ul>';
	}
	var intro = bum.util.parse(text, '<div class="content-items clear_fix" style="padding: 10px 0;border-top: 1px solid #e5e5e5;border-bottom:none;margin-top:10px">', '</div>').replace(
			/<[\/]{0,1}(iframe|a|font)[^><]*>/gi, "").replace(/style/g, 'styles').replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');

	var clip = {
		poster : poster,
		title : title,
		detail : detail,
		intro : intro
	};

	return clip;
};

// phim14 only
CLIP.Info.getChaps = function(text) {
	text = bum.util.parse(text, '<ul id="server_list">', '</ul>').replace(/class="selec" /g, '');

	var eps = [];
	$.each(text.split('<p class="listep"'), function(i, item) {
		if (i > 0) {
			var sName = bum.util.parse(item, "<span class='svname'>", ':</span>');
			eps.push('<div><p><b>' + sName + '</b></p></div>');

			var steps = bum.util.parse(item, "<span class='svep'>", '</span>');
			$.each(steps.split('</a>'), function(i, step) {
				if (step != '') {
					// http://m.phim14.net/xem-phim/anh-hung-du-con_black-white-the-dawn-of-justice.7546.177347.html
					var code = bum.util.parse(step, '<a href="', '"').replace('http://m.phim14.net/xem-phim/', '');
					var name = bum.util.parse(step, '">', null);
					eps.push('<a href="' + code + '">' + name + '</a>');
				}
			});
		}
	});

	var T = $('#chaps');
	if (T.length > 0) {
		$('#chaps').html(eps.join(''));
	} else {
		CLIP.Chap.chaps = eps.join('');
	}
};

CLIP.Clips.headers = [ 'Accept', 'text/plain, text/html', 'Host', 'phim14.net', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
		'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2150.5 Safari/537.36' ].join('|');
CLIP.Chap.headers = [ 'Accept', 'text/plain, text/html', 'Host', 'm.phim14.net', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
		'Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' ].join('|');

CLIP.Chap.chapUrl = function(code) {
	return 'http://m.phim14.net/xem-phim/' + code;
};
// custome
CLIP.Chap.streamUrl = function(text) {
	return bum.util.parse(text, 'var video_src_mv= "', '"');
};